package com.gbt32960;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.json.JSONObject;

import java.util.Map;

public class GBT32960DecodeFunc
        extends UDF
{
    public String evaluate(String reportHex)
    {
        if (reportHex == null || reportHex.isEmpty()) {
            return "{}";
        }
        if (reportHex.startsWith("2424") || reportHex.startsWith("2323")) {
            Map<String,Object> map = GBT32950Decoder.decode(reportHex);
            JSONObject json = new JSONObject(map);
            return json.toString();
        }
        else {
            return "{}";
        }
    }
}
